// 处理数据
let Main = {
  data: function() {
    return {
      resultData: {},
      tableData: [],
      dateValue: '',
      totalRows: 0,
      pageNum: 1, // 页码的参数名称，默认：page
      numPerPage: 20, // 每页数据量的参数名，默认：limit
      rankYear: '',
      rankMonth: '',
      userName: '',
      rankParentTypeIndex: 0
    }
  },
  created: function() {
    this.ajaxData()
  },
  methods: {
    rankingFn: function(val:number) {
      this.dateValue =''
      this.pageNum = 1
      this.numPerPage = 20
      this.rankYear = ''
      this.rankMonth = ''
      this.userName = ''
      this.rankParentTypeIndex = parseInt(val)
      this.ajaxData()
    },
    ajaxData() {
      let That = this
      $.ajax({
        type: 'get', //get或post
        url: url, //请求的地址
        data: {
          pageNum: this.pageNum, // 页码的字段
          numPerPage: this.numPerPage, // 每页数据量的字段
          rankYear: this.rankYear || '',
          rankMonth: this.rankMonth || '',
          userName: this.userName || '',
          organNbr: organNbr, // 接口验证字段
          rankParentType: rankParentTypes[this.rankParentTypeIndex] // 接口验证字段 (农户排名)
        },
        success: function(result:object) {
          this.resultData = result
          That.tableData = result.list // 数据列表
          That.totalRows = result.totalRows
          That.tableData = result.list
        }
      })
      if (That.tableData.length !== 0) {
        That.tableData.map((item, index) => {
          item.bak3 = item.bak3 + '%'
          item.bak2 = item.bak2 >= 100 ? '100%' : item.bak2 + '%'
        })
      }
    },
    handleCurrentChange(e:number) {
      // currentPage 改变时会触发
      this.pageNum = e + ''
      this.ajaxData()
    },
    handleSizeChange(e:number) {
      // pageSize 改变时会触发
      this.numPerPage = e + ''
      this.ajaxData()
    },
    selectDate(e:any) {
      if (e) {
        this.rankYear = e.getFullYear()
        this.rankMonth = e.getMonth() + 1
      } else {
        this.rankYear = ''
        this.rankMonth = ''
      }
    },
    searchFn() {
      this.ajaxData()
    }
  }
}
let Ctor = Vue.extend(Main)
new Ctor().$mount('#app')